#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a),i##END=(b);i<=i##END;i++)
#define Rof(i,b,a) for(int i=(b),i##END=(a);i>=i##END;i--)
#define go(u) for(int i=head[u];i;i=nxt[i])
#define int long long
using namespace std;
inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    return x*f;
}
const int N=1e5+10;
#define pi pair<int,int>
#define fi first
#define se second
int n;pi a[N];multiset<int> s;
signed main(){
	freopen("boast.in","r",stdin);
	freopen("boast.out","w",stdout);
	For(i,1,n=read()){int x=read(),y=read();a[i]=pi(y,x);}
	sort(a+1,a+1+n);For(i,1,n)s.insert(a[i].fi+a[i].se);
	int ans=1e18;For(i,1,n-2)s.erase(s.find(a[i].fi+a[i].se)),
		ans=min(ans,a[i].se+*s.begin()+*next(s.begin()));
	cout<<ans<<endl;
	return 0;
}
